/** @file               sw_module.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_MODULE_H__
#define __SW_MODULE_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef SW_VOID *SW_MODULE;
#define SW_INVALID_MODULE NULL

#ifdef WIN32
#define SW_MERR(module, format, ...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_ERR, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_RED, SW_DC_DEFAULT, format, __VA_ARGS__); \
}while(0)

#define SW_MWRN(module, format, ...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_WRN, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_YELLOW, SW_DC_DEFAULT, format, __VA_ARGS__); \
}while(0)

#define SW_MINF(module, format, ...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_INF, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_CYAN, SW_DC_DEFAULT, format, __VA_ARGS__); \
}while(0)

#define SW_MDBG(module, format, ...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_DBG, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_GREEN, SW_DC_DEFAULT, format, __VA_ARGS__); \
}while(0)

#define SW_MDEV(module, format, ...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_DEV, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_MAGENTA, SW_DC_DEFAULT, format, __VA_ARGS__); \
}while(0)
#else
#define SW_MERR(module, format, args...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_ERR, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_RED, SW_DC_DEFAULT, format, ##args); \
}while(0)

#define SW_MWRN(module, format, args...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_WRN, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_YELLOW, SW_DC_DEFAULT, format, ##args); \
}while(0)

#define SW_MINF(module, format, args...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_INF, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_CYAN, SW_DC_DEFAULT, format, ##args); \
}while(0)

#define SW_MDBG(module, format, args...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_DBG, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_GREEN, SW_DC_DEFAULT, format, ##args); \
}while(0)

#define SW_MDEV(module, format, args...) \
do \
{ \
    SW_ModulePrintf(module, SW_DL_DEV, __FILE__, __FUNCTION__, __LINE__, SW_DS_BRIGHT, SW_DC_MAGENTA, SW_DC_DEFAULT, format, ##args); \
}while(0)
#endif

#define SW_REGISTER_MODULE(module, name, level, major, minor, patch)  \
do \
{ \
    module = SW_CreateModule(name, level, major, minor, patch, __DATE__, __TIME__); \
} while (0);

#define SW_UNREGISTER_MODULE(module) \
do \
{ \
    SW_DeleteModule(module); \
    module = SW_INVALID_MODULE; \
}while(0)

SW_API SW_RET SW_InitModuleAPI(SW_VOID);
SW_API SW_RET SW_RunModuleAPI(SW_VOID);
SW_API SW_RET SW_StopModuleAPI(SW_VOID);
SW_API SW_RET SW_ExitModuleAPI(SW_VOID);
SW_API SW_MODULE SW_CreateModule(const SW_CHAR *pName, SW_DEBUG_LEVEL level, SW_UINT32 major, SW_UINT32 minor
                                 , SW_UINT32 patch, const SW_CHAR *pDateStr, const SW_CHAR *pTimeStr);
SW_API SW_RET SW_DeleteModule(SW_MODULE module);
SW_API SW_MODULE SW_FindModule(const SW_CHAR *pName);
SW_API SW_RET SW_SetModuleDebugLevel(SW_MODULE module, SW_DEBUG_LEVEL level);
SW_API SW_DEBUG_LEVEL SW_GetModuleDebugLevel(SW_MODULE module);
SW_API SW_RET SW_GetModuleName(SW_MODULE module, SW_CHAR *pName, SW_UINT32 nameLen);
SW_API SW_UINT32 SW_GetModuleMajor(SW_MODULE module);
SW_API SW_UINT32 SW_GetModuleMinor(SW_MODULE module);
SW_API SW_UINT32 SW_GetModulePatch(SW_MODULE module);
SW_API SW_RET SW_GetModuleBuild(SW_MODULE module, SW_DATETIME *pBuild);
SW_API SW_RET SW_ModulePrintf(SW_MODULE module, SW_DEBUG_LEVEL level, const SW_CHAR *pCodeFileName
                              , const SW_CHAR *pCodeFuncName, SW_UINT32 codeLine
                              , SW_DEBUG_STYLE style, SW_DEBUG_COLOR foreColor
                              , SW_DEBUG_COLOR backColor, const SW_CHAR *pFormat, ...)
#ifdef WIN32
                              ;
#else
                              __THROW __attribute__ ((__format__ (__printf__, 9, 10)));
#endif

#ifndef SW_V_DISABLE_CMDSERVER
SW_API SW_RET SW_CmdModule(SW_VOID);
SW_API SW_RET SW_CmdSetModuleDebugLevel(const SW_CHAR *pName, const SW_CHAR *pLevel);
#endif

#ifdef __cplusplus
}
#endif

#endif

